package com.pennapps;

import java.io.IOException;
import java.net.MalformedURLException;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import com.facebook.android.*;
import com.facebook.android.Facebook.*;

public class PennAppsActivity extends Activity {

    Facebook facebook = new Facebook("251963618210928");
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        final Button button = (Button) findViewById(R.id.loginButton);
        button.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
            	login();
            }
        });

        final Button button2 = (Button) findViewById(R.id.logoutButton);
        button2.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
            	logout();
            }
        });
    }

    protected void logout() {
    	 try {
    		        facebook.logout(getApplicationContext());
    		    } catch (MalformedURLException e) {
    		        e.printStackTrace();
    	    } catch (IOException e) {
    		        e.printStackTrace();
    		    }	}

	protected void login() {
    	 
        facebook.authorize(this, new DialogListener() {
            @Override
            public void onComplete(Bundle values) {}

            @Override
            public void onFacebookError(FacebookError error) {}

            @Override
            public void onError(DialogError e) {}

            @Override
            public void onCancel() {}
        });		
	}

	@Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        facebook.authorizeCallback(requestCode, resultCode, data);
    }
}